<template>
    <div>
        展示所有资源
       <van-checkbox-group v-model="ids" >
            <van-checkbox :name="i.id" v-for="i in resourcelist">{{i.name}}</van-checkbox>
       </van-checkbox-group>
       <button @click="add">添加</button>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                //获取上一个页面传递过来的id
                roleid:this.$route.query.id,
                resourcelist:[],
                ids:[]
            }
        },
        methods:{
            get_rolelist(){
                this.$axios.get('resourcesM')
                .then(res=>{
                     this.resourcelist=res.data.list
                     this.getResByid()
                })
               
            },
            add(){
                this.$axios.post('setresourcesM?',{'roleid':this.roleid,'ids':this.ids})
                .then(res=>{
                    if(res.data.code==200){
                        alert('添加成功')
                    }
                })
            },
            //查询此角色对应的资源ids
            getResByid(){
              this.$axios.get('resourcesM?id='+this.roleid)
                .then(res=>{
                     this.ids=res.data.list
                    
                })
            },
        },
        mounted(){
            this.get_rolelist()
           
        },
    }
</script>

<style scoped>

</style>